(function() {
  var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
    __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  this.ProfileRatedBooksView = (function(_super) {

    __extends(ProfileRatedBooksView, _super);

    function ProfileRatedBooksView() {
      this.afterLoad = __bind(this.afterLoad, this);
      return ProfileRatedBooksView.__super__.constructor.apply(this, arguments);
    }

    ProfileRatedBooksView.prototype.initialize = function() {
      ProfileRatedBooksView.__super__.initialize.apply(this, arguments);
      this.setElement("#main");
      this.model.bind("change", this.render);
      return this.render();
    };

    ProfileRatedBooksView.prototype.events = {
      "click .sorting a[data-sort-option]": "changeSortOption",
      "click .view-type img[data-view-type]": "changeViewType",
      "click .best-books-content ul.star-rating li a": "rate"
    };

    ProfileRatedBooksView.prototype.changeViewType = function(event) {
      var viewType;
      event.preventDefault();
      Loading.Start();
      viewType = $(event.target).data("view-type");
      this.model.setStaticProperty("BookViewType", viewType);
      this.model.set("Page", 1, {
        silent: true
      });
      this.renewScrolling();
      return this.model.fetch();
    };

    ProfileRatedBooksView.prototype.changeSortOption = function(event) {
      var column, direction;
      event.preventDefault();
      Loading.Start();
      column = $(event.target).data("sort-option");
      direction = $(event.target).data("sort-direction");
      this.model.setStaticProperty("Column", column);
      this.model.setStaticProperty("Direction", direction);
      this.model.set("Page", 1, {
        silent: true
      });
      this.renewScrolling();
      return this.model.fetch();
    };

    ProfileRatedBooksView.prototype.getTemplateUrl = function() {
      switch (this.model.get("BookViewType")) {
        case 0:
          return SiteMap.Profile.ListingIconViewTemplate;
        case 1:
          return SiteMap.Profile.ListingListViewTemplate;
        default:
          return '';
      }
    };

    ProfileRatedBooksView.prototype.rate = function(e) {
      var rating, ratingModel, ratingView, ul;
      e.preventDefault();
      rating = $(e.currentTarget);
      ul = rating.closest("ul.star-rating:not(.disabled)");
      if (ul.length > 0) {
        ratingModel = new RatingModel();
        ratingModel.set({
          "BookId": ul.data("val-bookid"),
          "RatingValue": rating.data("rate-value")
        });
        return ratingView = new RatingView({
          model: ratingModel,
          el: $(ul)
        });
      }
    };

    ProfileRatedBooksView.prototype.afterLoad = function(data) {
      var _this = this;
      return this.GetTemplate(this.getTemplateUrl(), function(compiledTemplate) {
        return $(_this.el).find("ul.listing").append(compiledTemplate({
          Items: data
        }));
      });
    };

    ProfileRatedBooksView.prototype.render = function() {
      var _this = this;
      this.Navigate(this.model.url(), false, true);
      return this.GetTemplate(SiteMap.Profile.RatedBooksTemplate, function(compiledTemplate) {
        $(_this.el).html(compiledTemplate(_this.model.toJSON()));
        _this.startLoading();
        return _this.renewScrolling();
      });
    };

    ProfileRatedBooksView.prototype.dispose = function() {};

    return ProfileRatedBooksView;

  })(ScrollPagingView);

}).call(this);
